<?php
/**
 * Created by PhpStorm.
 * User: 秋刀鱼
 * Date: 2018/8/17
 * Time: 13:29
 */

namespace backend\controllers;

use Yii;
use yii\web\Controller;
use yii\filters\VerbFilter;
use yii\filters\AccessControl;
use common\models\LoginForm;
use yii\db\query;
use yii\filters\Cors;
use yii\helpers\ArrayHelper;
use yii\web\models;
use \common\helps\tools;//使用工具类
use yii\db\ActiveRecord;
use yii\db\Connection;
use \app\models\Special;


/**
 * Special controller
 */
class SpecialController extends Controller
{

    public function init()
    {
        $this->enableCsrfValidation = false;
    }



    /**
     * {@inheritdoc}
     */
    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ];
    }

    /**
     * title 专家验收列表
     * @return string
     */
    public function actionSpeciallist()
    {
        return $this->render('specialchecklist');
    }

    /**
     * title 专家验收详情
     * @return string
     */
    public function actionDetailspecial()
    {
        return $this->render('specialcheck');
    }


    /**
     * title 专家验收保存
     * @return string
     */
    public function actionSavespecial()
    {
        return $this->render('savespecial');
    }


    /**
     * title 专家验收提交
     * @return string
     */
    public function actionSubmitspecial()
    {
        return $this->render('submitspecial');
    }

    /**
     * title 已验收列表
     * @return string
     */
    public function actionCheck()
    {
        return $this->render('submitspecial');
    }


    /**
     * title 已验收详情
     * @return string
     */
    public function actionDetailcheck()
    {
        return $this->render('detailsubmit');
    }


    /**
     * title 表单
     * @return string
     */
    public function actionTable()
    {
        header('Access-Control-Allow-Origin:*');
        $post = Yii::$app->request->post();
        $uid = $post['uid'];
        $token = $post['token'];
        //token验证
        $checkToken = tools::checkToken('admin_'.$uid,$token);
        if($checkToken != 4){
            return tools::ajax_return('9','token过期,请重新登录',[$checkToken]);
        }

        $table = new \app\models\Table;
        $line = $table->tableLine();

        if(!$line){
            return tools::ajax_return_error('1','失败',[]);
        }

        return tools::ajax_return('0','成功',$line);

    }


    /**
     * title 待验收列表
     * @return string
     */
    public function actionProjectPortList()
    {
        header('Access-Control-Allow-Origin:*');
        $post = Yii::$app->request->post();
        $uid = $post['uid'];
        $token = $post['token'];
        //token验证
        $checkToken = tools::checkToken('admin_'.$uid,$token);
        if($checkToken != 4){
            return tools::ajax_return_error('9','token过期,请重新登录',[$checkToken]);
        }

        $special = new \backend\models\Special;
        $list = $special->checkList($uid);

        if(!$list){
            return tools::ajax_return_error('0','成功',[]);
        }

        return tools::ajax_return('0','成功',$list);


    }



    /**
     * title 验收(编辑)
     * @return string
     */
    public function actionProjectPortCheck()
    {
        header('Access-Control-Allow-Origin:*');
        $post = Yii::$app->request->post();
        $uid = $post['uid'];
        $token = $post['token'];
        //token验证
        $checkToken = tools::checkToken('admin_'.$uid,$token);
        if($checkToken != 4){
            return tools::ajax_return_error('9','token过期,请重新登录',[$checkToken]);
        }

        $manage_id = $post['manage_id'];

        //调用model
        $checkSpecial = Special::checkSpecial($manage_id);
        if($checkSpecial == 2){
            return tools::ajax_return_error('1','失败',[]);
        }
        return tools::ajax_return('0','成功',$checkSpecial);


    }


    /**
     * title 验收保存
     * @return string
     */
    public function actionCheckPortSave()
    {
        header('Access-Control-Allow-Origin:*');
        $post = Yii::$app->request->post();
        $uid = $post['uid'];
        $token = $post['token'];
        //token验证
        $checkToken = tools::checkToken('admin_'.$uid,$token);
        if($checkToken != 4){
            return tools::ajax_return('9','token过期,请重新登录',[$checkToken]);
        }


        $user = $post['user'];//用户信息
        $manage = $post['manage'];//验收信息
        $table = $post['table'];//表列
        $detail = $post['detail'];//表内容

        $user = ['name'=>'111','phone'=>'18701626993','email'=>'','company'=>'','job'=>''];
        $manage = ['id'=>'84d88acfa591828fea93d7e56aa062a8','check_think'=>'验收意见2'];
        $table = [['content'=>'3123','pid'=>'0','level'=>'1','order'=>'1'],['content'=>'55555','pid'=>'0','level'=>'2','order'=>'1']];
        $detail = [['across'=>'1','endlong'=>'1','content'=>'123123123']];


        //调用model
        $special = new Special;
        $save = $special->checkSave($user,$manage,$table,$detail);
        if($save == 2){
            return tools::ajax_return_error('1','保存失败',[]);
        }
        return tools::ajax_return('0','保存成功',$check);

    }



}